﻿<UserControl 
    x:Class="ibba.src.noriskbo.views.childs.ImportarGarantias"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ig="http://schemas.infragistics.com/xaml"
    xmlns:vm="clr-namespace:ibba.src.noriskbo.ViewModels"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"  
    xmlns:behavior="clr-namespace:ibba.src.noriskbo.code.behavior"
    xmlns:slrv="clr-namespace:ibba.src.sl.recursos.Validations;assembly=ibba.src.sl.recursos"
    xmlns:slc="clr-namespace:ibba.src.sl.componentes;assembly=ibba.src.sl.componentes"
    xmlns:local="clr-namespace:ibba.src.noriskbo"
    mc:Ignorable="d"    
    d:DesignHeight="300" d:DesignWidth="800">

    <UserControl.Resources>        
        <vm:ImportarGarantiasViewModel x:Key="viewModel" />

        <DataTemplate x:Key="CustomRowTemplate">
            <Border CornerRadius="3">
                <Border.Effect>
                    <DropShadowEffect BlurRadius="10" Direction="270" Opacity="0.5" ShadowDepth="1" />
                </Border.Effect>
                <Border.Background>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                        <GradientStop Offset="0" Color="#FF555555" />
                        <GradientStop Offset="1" Color="Black" />
                        <GradientStop Offset="0.75" Color="#FF222222" />
                    </LinearGradientBrush>
                </Border.Background>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="1" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Path Height="30" Margin="1,1,1,0" VerticalAlignment="Top" 
                          Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2"
                          Data="M 4.64,1 C2.63,1 1,2.63 1,4.65 1,4.65 1,76 1,76 106.00,42.68 371.74,19.03 683,19.03 720.04,19.03 754.44,19.36 790,20.01 790,20.01 790,4.65 790,4.65 790,2.63 788.36,1 786.34,1 786.34,1 4.64,1 4.64,1 z" >
                        <Path.Fill>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                <LinearGradientBrush.GradientStops>
                                    <GradientStopCollection>
                                        <GradientStop Offset="0" Color="#7dffffff" />
                                        <GradientStop Offset="0.75" Color="#00ffffff" />
                                        <GradientStop Offset="1" Color="#00ffffff" />
                                    </GradientStopCollection>
                                </LinearGradientBrush.GradientStops>
                            </LinearGradientBrush>
                        </Path.Fill>
                    </Path>
                    <Border Margin="1,1,1,0" BorderThickness="0,1,0,0" CornerRadius="3" Grid.ColumnSpan="2" Grid.RowSpan="2">
                        <Border.BorderBrush>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                                <GradientStop Offset="0" Color="#59FFFFFF" />
                                <GradientStop Offset="1" Color="Transparent" />
                                <GradientStop Offset="0.5" Color="White" />
                            </LinearGradientBrush>
                        </Border.BorderBrush>
                    </Border>

                    <Grid Background="White" Grid.Row="1" d:LayoutOverrides="GridBox" Margin="20" VerticalAlignment="Center" HorizontalAlignment="Left">
                        <Grid Margin="1" Background="#FF929191">
                            <Image Source="{Binding StatusImportacao}" MaxWidth="100" Margin="1" Grid.Column="0" Grid.Row="0" />
                        </Grid>
                    </Grid>
                    <Grid Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Left">
                        <Grid VerticalAlignment="Top">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="20" />
                                <!--<RowDefinition Height="20" />
                                <RowDefinition Height="20" />
                                <RowDefinition Height="20" />
                                <RowDefinition Height="20" />-->
                            </Grid.RowDefinitions>

                            <!--<TextBlock x:Name="Contact_Name" Text="{Binding ContactName}" HorizontalAlignment="Left" VerticalAlignment="Center" 
                                       Grid.ColumnSpan="2" Foreground="#FFFFFFFF" FontSize="20" FontFamily="Segoe UI" />-->
                            <TextBlock Text="Erro" 
                                       Foreground="White" TextWrapping="Wrap" 
                                       HorizontalAlignment="Left" 
                                       Margin="0,0,5,0" Opacity="0.5" Grid.Row="1" />
                            <TextBlock x:Name="Customer_ID" Text="{Binding DescricaoErro}" Foreground="White"                                        
                                       HorizontalAlignment="Left" VerticalAlignment="Top" 
                                       Grid.Row="1" Grid.Column="1" />
                            <!--<TextBlock x:Name="Title" Text="{Binding ContactTitle}" Foreground="White"                                        
                                       HorizontalAlignment="Left" VerticalAlignment="Top" 
                                       Grid.Row="2" Grid.Column="1" />
                            <TextBlock x:Name="Country" Text="{Binding Country}" Foreground="White"
                                       HorizontalAlignment="Left" VerticalAlignment="Top" 
                                       Grid.Row="3" Grid.Column="1" />
                            <TextBlock x:Name="Phone" Text="{Binding Phone}" Foreground="White"
                                       Grid.Column="1" Grid.Row="4" 
                                       HorizontalAlignment="Left" VerticalAlignment="Top" />-->

                            <!--<TextBlock Text="{Binding Path=XWG_Customers_ContactTitle, Source={StaticResource Strings}}" 
                                       Foreground="White" TextWrapping="Wrap" 
                                       HorizontalAlignment="Left" 
                                       Margin="0,0,5,0" Opacity="0.5" Grid.Row="2" />
                            <TextBlock Text="{Binding Path=XWG_Customers_Location, Source={StaticResource Strings}}" 
                                       Foreground="White" TextWrapping="Wrap" 
                                       HorizontalAlignment="Left" 
                                       Margin="0,0,5,0" Opacity="0.5" Grid.Row="3" />
                            <TextBlock Text="{Binding Path=XWG_Customers_Phone, Source={StaticResource Strings}}" 
                                       Foreground="White" TextWrapping="Wrap" 
                                       HorizontalAlignment="Left" VerticalAlignment="Top" 
                                       Margin="0,0,5,0" Opacity="0.5" Grid.Row="4" />-->
                        </Grid>
                    </Grid>
                </Grid>
            </Border>
        </DataTemplate>

    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White" Margin="3,3,3,20" DataContext="{Binding Source={StaticResource viewModel}}">
        <toolkit:BusyIndicator IsBusy="{Binding IsBusy}" BusyContent="{Binding BusyText}">

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Grid.Row="0">
                    <StackPanel Orientation="Vertical" Margin="0,0,0,2" VerticalAlignment="Bottom">
                        <StackPanel Orientation="Horizontal" VerticalAlignment="Bottom">
                            <TextBlock Text="Arquivo:" Style="{StaticResource SubTitleHeader}" VerticalAlignment="Center" FontSize="10"/>
                            <TextBlock Text="{Binding ExcelFileName}" Margin="5,0,0,0" Foreground="#FF0A739D" FontSize="10" />
                        </StackPanel>
                    </StackPanel>
                </StackPanel>

                <Grid Grid.Row="0" Grid.RowSpan="2" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,-40,150,0">
                    <TextBlock Text="Garantias" Style="{StaticResource TitlePage}" Margin="0,-10,0,0" FontSize="56" FontFamily="Arial Black" FontStyle="Italic" />
                </Grid>

                <Grid Name="gridDados" Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <ig:XamGrid x:Name="xgDados" Grid.Row="1" Margin="0,0,0,29" 
                                ItemsSource="{Binding DadosPlanilha}"                                
                                AutoGenerateColumns="False"
                                RowAdded="xgDados_RowAdded"
                                RowDeleted="xgDados_RowDeleted"
                                RowEnteredEditMode="xgDados_RowEnteredEditMode"
                                DeleteKeyAction="DeleteSelectedRows"
                                SelectedRowsCollectionChanged="xgDados_SelectedRowsCollectionChanged"
                                >
                        <!--<ig:XamGrid.ClipboardSettings>
                        <ig:ClipboardSettings AllowCopy="True" CopyOptions="IncludeHeaders" CopyType="SelectedCells" />
                    </ig:XamGrid.ClipboardSettings>-->

                        <i:Interaction.Behaviors>
                            <behavior:XamGridBehavior x:Name="xgDadosBehavior" IsExpandRowGrouped="True" IsHeaderCopyToClibboard="True" />
                        </i:Interaction.Behaviors>

                        <ig:XamGrid.SelectionSettings>
                            <ig:SelectionSettings CellClickAction="SelectRow" RowSelection="Multiple" />
                        </ig:XamGrid.SelectionSettings>

                        <ig:XamGrid.RowSelectorSettings>
                            <ig:RowSelectorSettings Visibility="Visible" />
                        </ig:XamGrid.RowSelectorSettings>

                        <ig:XamGrid.AddNewRowSettings>
                            <ig:AddNewRowSettings AllowAddNewRow="Top" IsEnterKeyEditingEnabled="True" IsF2EditingEnabled="True" 
                                              IsMouseActionEditingEnabled="SingleClick" IsOnCellActiveEditingEnabled="False" 
                                              Style="{StaticResource AddRowStyling}" />
                        </ig:XamGrid.AddNewRowSettings>

                        <ig:XamGrid.EditingSettings>
                            <ig:EditingSettings AllowEditing="Row" IsEnterKeyEditingEnabled="True" IsF2EditingEnabled="True"
                                            IsMouseActionEditingEnabled="DoubleClick" IsOnCellActiveEditingEnabled="False" />
                        </ig:XamGrid.EditingSettings>

                        <ig:XamGrid.Columns>

                            <ig:TemplateColumn Key="StatusImportacao" IsResizable="False" HeaderStyle="{StaticResource GrayHeaderStyle}">
                                <ig:TemplateColumn.HeaderTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="SV" ToolTipService.ToolTip="Status de Validação"/>
                                    </DataTemplate>
                                </ig:TemplateColumn.HeaderTemplate>
                                <ig:TemplateColumn.ItemTemplate>
                                    <DataTemplate>
                                        <Image Source="{Binding StatusImportacao, Converter={StaticResource StatusImportToImageConverter}}"
                    					Width="22" Height="22" ToolTipService.ToolTip="{Binding DescricaoErro}"
                    					HorizontalAlignment="Center"/>
                                    </DataTemplate>
                                </ig:TemplateColumn.ItemTemplate>
                            </ig:TemplateColumn>

                            <!--<ig:GroupColumn Key="ChaveOperacao" HeaderText="Chave da Operação/Garantia" >
                            <ig:GroupColumn.Columns>-->
                            <ig:TextColumn Key="Numero" HeaderText="Nº " HeaderStyle="{StaticResource BlueHeaderStyle}" />
                            <ig:TextColumn Key="CodigoContrato" HeaderText="Contrato" Width="120" HeaderStyle="{StaticResource BlueHeaderStyle}" />
                            <ig:TextColumn Key="CodigoProduto" HeaderText="Produto" Width="100" HeaderStyle="{StaticResource BlueHeaderStyle}" />
                            <ig:TextColumn Key="CodigoModalidade" HeaderText="Modalidade" Width="100" HeaderStyle="{StaticResource BlueHeaderStyle}" />
                            <ig:TextColumn Key="IdCliente" HeaderText="Id Cliente" HeaderStyle="{StaticResource BlueHeaderStyle}" />
                            <ig:TextColumn Key="NomeCliente" HeaderText="Nome Cliente" IsReadOnly="True" CellStyle="{StaticResource CellColumnStyle}" HeaderStyle="{StaticResource BlueHeaderStyle}"/>
                            <!--</ig:GroupColumn.Columns>
                        </ig:GroupColumn>-->

                            <!--<ig:GroupColumn Key="Trinca" HeaderText="Trinca da Garantia" >
                            <ig:GroupColumn.Columns>-->
                            <ig:TextColumn Key="Instrumento" HeaderText="Instrumento" HeaderStyle="{StaticResource OrangeHeaderStyle}"/>
                            <ig:TextColumn Key="Bem" HeaderText="Bem" HeaderStyle="{StaticResource OrangeHeaderStyle}"/>
                            <ig:TextColumn Key="Natureza" HeaderText="Natureza" HeaderStyle="{StaticResource OrangeHeaderStyle}"/>
                            <!--</ig:GroupColumn.Columns>
                        </ig:GroupColumn>-->

                            <!--<ig:TextColumn Key="DataAbertura" HeaderText="Abertura" Width="130" FormatString="{}{0:d}" />-->
                            <ig:TextColumn Key="Descricao" HeaderText="Descrição" Width="130" HeaderStyle="{StaticResource GrayHeaderStyle}"/>
                            <ig:DateColumn Key="DataVencimento" HeaderText="Vencimento" Width="130" HeaderStyle="{StaticResource GrayHeaderStyle}"/>
                            <ig:TextColumn Key="CodigoMoeda" HeaderText="Moeda" HeaderStyle="{StaticResource GrayHeaderStyle}"/>
                            <ig:TextColumn Key="ValorOriginal" HeaderText="Vlr. Original" FormatString="{}{0:N2}" HeaderStyle="{StaticResource GrayHeaderStyle}"/>
                            <ig:TextColumn Key="ValorAtualizado" HeaderText="Vlr. Atualizado" FormatString="{}{0:N2}" HeaderStyle="{StaticResource GrayHeaderStyle}"/>
                            <ig:CheckBoxColumn Key="Formalizada" IsFilterable="False" IsGroupable="False" IsResizable="False" HeaderStyle="{StaticResource GrayHeaderStyle}">
                                <ig:CheckBoxColumn.HeaderTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="GF" ToolTipService.ToolTip="Garantia Formalizada"/>
                                    </DataTemplate>
                                </ig:CheckBoxColumn.HeaderTemplate>
                            </ig:CheckBoxColumn>

                            <ig:CheckBoxColumn Key="SobrepoeAutomatica" IsFilterable="False" IsGroupable="False" IsResizable="False" HeaderStyle="{StaticResource GrayHeaderStyle}">
                                <ig:CheckBoxColumn.HeaderTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="SA" ToolTipService.ToolTip="Sobrepor a Garantia Automática"/>
                                    </DataTemplate>
                                </ig:CheckBoxColumn.HeaderTemplate>
                            </ig:CheckBoxColumn>
                                                        
                            <!--<ig:TemplateColumnLayout Key="CustomerID" Template="{StaticResource CustomRowTemplate}" Visibility="{Binding HasItemError, Converter={StaticResource BooleanToVisibilityConverter}}" />-->
                        </ig:XamGrid.Columns>
                    </ig:XamGrid>

                    <local:PainelListaGarantidores x:Name="painelGarantidores" Grid.Column="1" Margin="1,0,0,30" DataContext="{Binding Source={StaticResource viewModel}}" 
                                                   HiddenList="{Binding IsValidated, Converter={StaticResource NotBooleanConverter}, FallbackValue=True}"/>
                    
                    <!--<Border Grid.Column="1" Background="#FFE8E5E5" BorderBrush="Silver" Margin="1,0,0,30" Padding="5">
                        <Grid>
                            <Border Background="White" CornerRadius="10" />
                            
                            <TextBlock Text="Garantidores" Foreground="#FFD5D7D8" Margin="5,-8,0,0"
                                       HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="24" FontFamily="Arial Black"  />

                            <ListBox Margin="3,18,3,3" BorderBrush="Silver"
                                     ItemsSource="{Binding SelectionSettings.SelectedRows[0].Data.Garantidores, ElementName=xgDados}">
                                                                
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <Grid Margin="1">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <Grid.RowDefinitions>
                                                <RowDefinition/>
                                                <RowDefinition Height="Auto"/>
                                            </Grid.RowDefinitions>

                                            <Border Grid.Row="1" Grid.ColumnSpan="2" 
                                                Style="{StaticResource LineBlue}" 
                                                Width="320" Margin="3" HorizontalAlignment="Center"/>

                                            <StackPanel Orientation="Vertical">
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBox Background="Transparent" BorderThickness="0" Width="230" Text="{Binding Nome}" IsReadOnly="True" Style="{StaticResource TextReadOnly}" />
                                                </StackPanel>
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock Text="ID:" FontFamily="Arial Black" Width="40" Foreground="Gray" VerticalAlignment="Center"/>
                                                    <TextBox Background="Transparent" BorderThickness="0" Width="50" Text="{Binding IdPessoa, Mode=TwoWay}" slrv:TextBoxFilterService.Filter="PositiveInteger" />
                                                </StackPanel>
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock Text="{Binding TipoPessoa, Converter={StaticResource LabelDocConverter}}" FontFamily="Arial Black" Width="40" Foreground="Gray" VerticalAlignment="Center"/>
                                                    <TextBox Background="Transparent" BorderThickness="0" Width="120" Text="{Binding CpfCnpj, Converter={StaticResource FormatCnpjCpfConverter}, ConverterParameter={Binding TipoPessoa}}" IsReadOnly="True" Style="{StaticResource TextReadOnly}" />
                                                </StackPanel>
                                            </StackPanel>

                                            <StackPanel Orientation="Horizontal" Grid.Column="1">
                                                <Border Style="{StaticResource LineBlue}" Width="1" Height="60" Margin="3,0" 
                                                VerticalAlignment="Center" HorizontalAlignment="Center"/>
                                                <StackPanel Orientation="Vertical">
                                                    <TextBlock Text="% Garantido" Padding="3" FontFamily="Arial Black" Foreground="Gray" VerticalAlignment="Center"/>
                                                    <TextBox Text="{Binding PercentualGarantidor, Mode=TwoWay, StringFormat=\{0:n0\}}" Padding="0,-8" Height="40" FontFamily="Arial Black" FontSize="35" Margin="5,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Transparent" BorderThickness="0"
                                                             slrv:TextBoxFilterService.Filter="PositiveInteger"/>
                                                    
                                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                                                        <Image Name="imgExcluirGarantidor" Source="{Binding FlagExcluir, Converter={StaticResource CheckExcluirConverter}}" 
                                                           HorizontalAlignment="Right" Width="12" Margin="8,0,0,0"
                                                           MouseLeftButtonUp="imgExcluirGarantidor_MouseLeftButtonUp" 
                                                           ToolTipService.ToolTip="Marcar para excluir!" />
                                                    </StackPanel>
                                                </StackPanel>
                                            </StackPanel>
                                        </Grid>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                                     
                            </ListBox>
                        </Grid>
                    </Border>-->
                    
                </Grid>
                <Border Background="#FFEFEFEF" BorderThickness="1,1,1,1" BorderBrush="#FF617583" Height="30" 
                        HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Grid.Row="1" Padding="3" >
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <HyperlinkButton x:Name="lnkDownload" Content="Baixar Planilha Template" VerticalAlignment="Center" HorizontalAlignment="Left"
                                         Foreground="#FF0E50DE" TargetName="_blank" />

                        <StackPanel Orientation="Horizontal" Grid.Column="1">
                            <StackPanel Orientation="Horizontal" ToolTipService.ToolTip="Inclusão de uma nova operação manual">
                                <Image Source="{StaticResource IconeStatusImportIncluir}" Width="16" Height="16" Margin="0,4,0,0"/>
                                <TextBlock Text="Inclusão" VerticalAlignment="Center" Margin="3,8,25,3" />
                                <sdk:Label Content="{Binding InsertCount}" Style="{StaticResource LegendGreen}" Margin="-182,-18,0,0" />
                            </StackPanel>

                            <StackPanel Orientation="Horizontal" ToolTipService.ToolTip="Alteração de uma operação manual não aprovada">
                                <Image Source="{StaticResource IconeStatusImportAlterar}" Width="16" Height="16" Margin="0,4,0,0"/>
                                <TextBlock Text="Alteração" VerticalAlignment="Center" Margin="3,8,25,3" />
                                <sdk:Label Content="{Binding UpdateCount}" Style="{StaticResource LegendBlue}" Margin="-192,-18,0,0" />
                            </StackPanel>

                            <StackPanel Orientation="Horizontal" ToolTipService.ToolTip="Inclusão de copia de uma operação automática ou manual aprovada">
                                <Image Source="{StaticResource IconeStatusImportCopiar}" Width="16" Height="16" Margin="0,4,0,0"/>
                                <TextBlock Text="Copia" VerticalAlignment="Center" Margin="3,8,25,3" />
                                <sdk:Label Content="{Binding CopyCount}" Style="{StaticResource LegendGray}" Margin="-152,-18,0,0" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" ToolTipService.ToolTip="Indicador de ocorrência de erro na validação">
                                <Image Source="{StaticResource IconeStatusImportErro}" Width="16" Height="16" Margin="0,4,0,0" />
                                <TextBlock Text="Erro" VerticalAlignment="Center" Margin="3,8,25,3" />
                                <sdk:Label Content="{Binding ErrorCount}" Style="{StaticResource LegendRed}" Margin="-136,-18,0,0" />
                            </StackPanel>
                        </StackPanel>
                    </Grid>
                </Border>

                <TextBlock Style="{StaticResource SubTitlePage}" Text="{Binding NeedProcessCount, FallbackValue='100'}" 
                           Grid.Row="0" Grid.RowSpan="2" HorizontalAlignment="Right" Margin="0,-42,0,0"
                           Visibility="{Binding NeedProcessCount, Converter={StaticResource BooleanToVisibilityConverter}}"/>


            </Grid>

        </toolkit:BusyIndicator>
    </Grid>
</UserControl>

